#include "PropertyManager.h"

PropertyManager::PropertyManager()
    : editor_(nullptr)
{
}

PropertyManager& PropertyManager::get(const QString& name)
{
    static map<QString, PropertyManager> managers;
    auto that = managers.find(name);
    if (that == managers.end()) {
        managers[name] = PropertyManager();
        return managers.find(name)->second;
    }
    return that->second;
}

void PropertyManager::init(QtTreePropertyBrowser* editor)
{
    editor_ = editor;
}

void PropertyManager::setCurrent(shared_ptr<PropertyProvider> provider)
{
    if (provider_) {
        provider_->close();
        provider_.reset();
    }
    editor_->clear();
    provider_ = provider;
    provider->initEditor(editor_);
}


void PropertyManager::close()
{
    if (provider_) {
        provider_->close();
        provider_.reset();
    }
}
